<?php

/**
 * @author thihien
 * @copyright 2011
 */
require_once('includes/general.php');
if(!tep_db_checkDb()) die('khong ket noi dc csdl');
$sql='SELECT count(id) as count FROM `sanpham` ';
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=2;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from sanpham limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
$content='';
$content.='
    <div id="center" >
        <div id="tt_sanpham">
            <div class="title"><h3>products </h3></div>';
        while($item=tep_db_fetch_array($kq4)){
            $content.='
             
            <div id="sanpham">
                <div id="hinhanh1"><a href="?masp='.$item['id'].'&madanhmucsp='.$item['madanhmuc'].'&mode=detail"><img  height="120" src="admin/upload/'.$item['hinhanh'].'"/></a></div>
                <div id="tensp1">'.$item['tensanpham'].'</div>
                <div id="gia1" style="color: red;" > Your Price:$'.$item['gia'].'.00</div>
                <div><a href="?masp='.$item['id'].'&madanhmucsp='.$item['madanhmuc'].'&mode=detail"">detail...</a></div>
            </div>
                
                ';
                
        }
        
$content.='
        <ul id="phantrang">';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
                if($current!=1){
                   $content.='<li><a href="?page=sanpham&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?page=sanpham&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?page=sanpham&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?page=sanpham&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li><a href="?page=sanpham&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>
        </div>
        
    </div> 
';

echo $content;
?>

